﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using LunwenYun.Infrastructure.Entities.Repository;
using LunwenYun.Infrastructure.Entities.Cache;

namespace LunwenYun.Infrastructure.Entities.Entity
{
    public class IndustryCS : IAccessible<T_IndustryCS, IndustryCS>, ILogicEntity<T_IndustryCS, IndustryCS>
    {
        #region Fileds
        public string UserName { get; set; }
        /// <summary>
        /// 行业
        /// </summary>
        public string Industry { get; set; }
        
        /// <summary>
        /// 承办机构
        /// </summary>
        public int Organization { get; set; }

        /// <summary>
        /// 客服类型（称谓）
        /// </summary>
        public string Title { get; set; }

        public string QQ { get; set; }

        public string Phone { get; set; }

        public bool Enable { get; set; }

        public DateTime CreateTime { get; set; }
        #endregion

        public User User { get; set; }
        public string OrganizationName { get; set; }

        protected override void Covariant(T_IndustryCS model)
        {
            if (model != null)
            {
                this.CreateTime = model.CreateTime;
                this.Enable = model.Enable;
                this.Industry = model.Industry;
                this.Organization = model.Organization;
                this.Phone = model.Phone;
                this.QQ = model.QQ;
                this.Title = model.Title;
                this.UserName = model.UserName;
            }
        }

        protected override T_IndustryCS Inverter(IndustryCS model)
        {
            if (model != null)
            {
                return new T_IndustryCS()
                {
                    CreateTime = model.CreateTime,
                    Enable = model.Enable,
                    Industry = model.Industry,
                    Organization = model.Organization,
                    Phone = model.Phone,
                    QQ = model.QQ,
                    Title = model.Title,
                    UserName = model.UserName
                };
            }
            return null;
        }

        public IndustryCS Set(T_IndustryCS dbModel)
        {
            Covariant(dbModel);
            return this;
        }

        public IndustryCS SetOrganiztionName(string organizationName)
        {
            this.OrganizationName = organizationName;
            return this;
        }

        public IndustryCS LoadUser(T_User user)
        {
            this.User = new User().Set(user);
            return this;
        }

        /// <summary>
        /// 将启用缓存,通过username查找
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public override IndustryCS Find(string key)
        {
            return new IndustryCSCache().GetItem(key);
        }
        public override IndustryCS PostDelete()
        {
            new IndustryCSCache().RefreshItem(UserName);
            return base.PostDelete();
        }
        public override IndustryCS PostModify()
        {
            new IndustryCSCache().RefreshItem(UserName);
            return base.PostModify();
        }
    }
}
